package com.yss.kettle.service.impl;

import java.util.List;
        import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import com.yss.common.core.utils.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yss.kettle.service.IJobParamService;
import com.yss.kettle.mapper.JobParamMapper;
import com.yss.kettle.domain.JobParam;

/**
 * kettle参数信息Service业务层处理
 *
 * @author yss
 * @date 2023-04-23
 */
@Slf4j
@Service
public class JobParamServiceImpl extends ServiceImpl<JobParamMapper,JobParam> implements IJobParamService {
    /**
     * 查询kettle参数信息列表
     *
     * @param jobParam kettle参数信息
     * @return kettle参数信息
     */
    @Override
    public List<JobParam> selectJobParamList(JobParam jobParam) {
        QueryWrapper<JobParam> wrapper = new QueryWrapper();
        if (StringUtils.isNull(jobParam)) {
            return this.list(wrapper);
        }
        if (StringUtils.isNotEmpty(jobParam.getKeyName())) {
            wrapper.like("KEY_NAME", jobParam.getKeyName());
        }
        if (StringUtils.isNotEmpty(jobParam.getChineseName())) {
            wrapper.eq("CHINESE_NAME", jobParam.getChineseName());
        }
        if (null != jobParam.getStatus()) {
            wrapper.eq("STATUS", jobParam.getStatus());
        }
        return this.list(wrapper);
    }


    /**
     * 校验英文名称是否唯一
     *
     * @param   jobParam
     * @return 结果
     */
    @Override
    public boolean checkJobParamKeyNameUnique(JobParam jobParam) {
        String tableId = StringUtils.isNull(jobParam.getId()) ? "-1" : jobParam.getId();
        QueryWrapper<JobParam> wrapper = new QueryWrapper<>();
        wrapper.eq("KEY_NAME", jobParam.getKeyName());
        JobParam info = this.getOne(wrapper);
        if (StringUtils.isNotNull(info) && !info.getId().equals(tableId)) {
            return false;
        }
        return true;
    }
}
